package org.example.system.service.impl;

import org.example.commons.entity.SysFeedback;
import org.example.system.repository.SysFeedbackRepository;
import org.example.system.service.ISysFeedbackService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * 用户反馈 服务层
 *
 * @author bothin
 */
@Service
public class SysFeedbackServiceImpl implements ISysFeedbackService {
    @Autowired
    private SysFeedbackRepository feedbackRepository;

    @Override
    public SysFeedback queryById(Long id) {
        return feedbackRepository.findById(id).orElse(null);
    }

    @Override
    public Page<SysFeedback> queryAllPage(Pageable pageable) {
        return feedbackRepository.findAll(pageable);
    }

    @Override
    public SysFeedback insert(SysFeedback entity) {
        return feedbackRepository.save(entity);
    }

    @Override
    public SysFeedback update(SysFeedback entity) {
        return feedbackRepository.save(entity);
    }

    @Override
    public void deleteById(Long id) {
        feedbackRepository.deleteById(id);
    }

    @Override
    public Page<SysFeedback> searchList(String name, String content, Date[] dates, Pageable pageable) {
        return feedbackRepository.searchList("%"+name+"%","%"+content+"%",dates,pageable);
    }

    @Override
    public List<SysFeedback> queryAll() {
        return feedbackRepository.findAll();
    }

    @Override
    public List<SysFeedback> findByFeedbackIdIn(Long[] ids) {
        return feedbackRepository.findByFeedbackIdIn(ids);
    }

    @Override
    public List<SysFeedback> queryLastFeedBydays(Integer days) {
        return feedbackRepository.findLastFeedback(days);
    }
}
